//
//  MyFruitOrderListViewController.m
//  HuiMWorld
//
//  Created by chirui on 2018/1/31.
//  Copyright © 2018年 Shui. All rights reserved.
//

#import "MyFruitOrderListViewController.h"
#import "HTHorizontalSelectionList.h"
#import "OrderTableViewCell.h"
#import "FruitOrderDetailsViewController.h" // 详情
//#import "SellOrderFinishDetailsViewController.h"  // 带评价详情
#import "ShopPayForViewController.h"
//#import "SellCommentOrderViewController.h"
#import "FruitOrderFinishDetailsVC.h" //完成订单
#import "FruitOrderEmsDetailsVC.h" // 已发货订单
#import "FruitCommentOrderViewController.h"  //评论订单


@interface MyFruitOrderListViewController ()<HTHorizontalSelectionListDataSource,HTHorizontalSelectionListDelegate,UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
{
    //创建的ui
    UIScrollView * _topScrollView;
    UIScrollView * _scrollView;//内容上的滑块
    NSArray * _titileArray;
    UITableView * _tableView;
    CGPoint _point; //设置偏移量时使用
    int _totailPage;
    int _page;
    NSString * typeStr;
    
    UIView * noBodyView;
    UIView * commentBgView;
    
    NSDictionary * currySectionDic;   // 评价订单字典
    NSDictionary * curryRowDic;
    
    NSMutableArray * allOrderArray;
    NSArray * statusArray;
    
}
@property(nonatomic,strong)HTHorizontalSelectionList * selectionList;
@property (nonatomic,strong) SZTextView * sztTextView;


@end

@implementation MyFruitOrderListViewController


-(void)viewWillAppear:(BOOL)animated {
    
//    [_selectionList setSelectedButtonIndex:_index animated:YES];
//    _scrollView.contentSize =CGSizeMake(WIDTH*_index, 0);
//    _scrollView.contentOffset = CGPointMake(WIDTH*_index, 0);
//    
//    UITableView *tableViwe=(id)[self.view viewWithTag:1000+_index];
//    [tableViwe reloadData];
}

-(void)creatCommentView{
    
    
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    
    commentBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    commentBgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    [window addSubview:commentBgView];
    
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(60, HEIGHT/2-70, WIDTH - 120, 180)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8.f;
    bgView.layer.masksToBounds = YES;
    [commentBgView addSubview:bgView];
    
    UILabel * titlelabel  =[[UILabel alloc]initWithFrame:CGRectMake(0, 10, WIDTH - 120, 20)];
    titlelabel.text = @"立即评价";
    titlelabel.textAlignment = NSTextAlignmentCenter;
    titlelabel.font = [UIFont systemFontOfSize:16];
    [bgView addSubview:titlelabel];
    
    self.sztTextView =[[SZTextView alloc]initWithFrame:CGRectMake(10, 40, WIDTH, 100)];
    self.sztTextView.placeholder = @"请输入评价内容";
    self.sztTextView.font =[UIFont systemFontOfSize:15];
    [bgView addSubview:self.sztTextView];
    
    UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 140, WIDTH - 120, 0.5)];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [bgView addSubview:lineView];
    
    UIView * lineView_two = [[UIView alloc]initWithFrame:CGRectMake((WIDTH - 120)/2, 140,0.5,40)];
    lineView_two.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [bgView addSubview:lineView_two];
    
    UIButton * sureBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    sureBtn.frame = CGRectMake(0, 141,(WIDTH - 120)/2-0.5 , 39);
    [sureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    sureBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(sureCick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:sureBtn];
    
    UIButton * cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    cancelBtn.frame = CGRectMake((WIDTH - 120)/2, 141,(WIDTH - 120)/2 , 39);
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelCick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:cancelBtn];
    
}

-(void)sureCick{
    
    [self.sztTextView resignFirstResponder];
    
    if (self.sztTextView.text.length<=0) {
        
        [MBProgressHUD showMessag:@"请输入评论内容" withDelay:0 toView:self.view withMode:MBProgressHUDModeText hideWithDelay:1.5];
        return;
    }else {
        
        [commentBgView removeFromSuperview];
        [self requestMessageForNetOrdSn:@"" andProductStr:@""];
    }
    
}

-(void)cancelCick{
    
    [commentBgView removeFromSuperview];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img_nav_bg"] forBarMetrics:UIBarMetricsDefault];
    
    _page =1;
    typeStr = [NSString stringWithFormat:@"%ld",self.index];
    allOrderArray = @[].mutableCopy;
    
    
    noBodyView = [NothingMessageView creatNothingMessageViewFrame:CGRectMake(WIDTH/2-100, (HEIGHT-64)/2-150, 200, 200) andMessageStr:@"没有相关内容！" onView:nil];
    
    
    self.view.userInteractionEnabled=YES;
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.navigationItem.titleView=[TopLabel withLabelWithLabelText:@"我的订单"];
    
    
    _titileArray =@[@"全部",@"待付款",@"待发货",@"待收货",@"待评价",@"已完成"];
    statusArray = @[@"all",@"unpay",@"payed",@"deliver",@"wait_comment",@"done"];
    
    typeStr = statusArray[self.index];
    [self creatUI];
    [self requestDataForNet]; // 拉取全部数据
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_nav_renter" target:self action:@selector(backBtnClick)];
}

-(void)backBtnClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

//第三方库的使用

-(void)creatUI{
    //标题的ScrollView
    
    self.edgesForExtendedLayout =UIRectEdgeNone;
    
    _selectionList =[[HTHorizontalSelectionList alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    _selectionList.dataSource=self;
    _selectionList.delegate=self;
    [self.view addSubview:_selectionList];
    [_selectionList setTitleFont:[UIFont systemFontOfSize:17] forState:UIControlStateSelected];
    [_selectionList setTitleFont:[UIFont systemFontOfSize:16] forState:UIControlStateNormal];
    [_selectionList setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_selectionList setTitleColor:NavBackColor forState:UIControlStateSelected];
    //设置button之间的间距
    float WidthBtnFloat;
    if (ISP4||ISP5) {
        WidthBtnFloat =5;
    }else if (ISP6){
        WidthBtnFloat =10;
    }else {
        WidthBtnFloat =15;
    }
    UIView * line =[[UIView alloc]initWithFrame:CGRectMake(0, 49, WIDTH, 1)];
    line.backgroundColor =Color(248, 248, 248);
    [_selectionList addSubview:line];
    _selectionList.buttonInsets= UIEdgeInsetsMake(5,WidthBtnFloat, 5, WidthBtnFloat);
    //滑动按钮下边的滑块设置
    _selectionList.selectionIndicatorColor = NavBackColor;
    _selectionList.selectionIndicatorHeight =3;
    _selectionList.bottomTrimColor =[UIColor whiteColor];
    
    _tableView =[[UITableView alloc]initWithFrame:CGRectMake( 0, 50,WIDTH, HEIGHT- SH_TopHeight-50) style:UITableViewStyleGrouped];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [self.view addSubview:_tableView];
    
    [_tableView registerNib:[UINib nibWithNibName:@"OrderTableViewCell" bundle:nil] forCellReuseIdentifier:[OrderTableViewCell reuseIdentifier]];
    
    MJRefreshNormalHeader * header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        _page =1;
        [self requestDataForNet];
        
    }];
    _tableView.mj_header =header;
    
    MJRefreshAutoNormalFooter *  footer =[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        _page++;
        
        [self requestDataForNet];
        
    }];
    
    footer.automaticallyRefresh = YES;
    _tableView.mj_footer =footer;
    _tableView.mj_footer.hidden = YES;
    
}

#pragma mark------HTHorizontalSelectionListDelegate实现--
//点击效果
-(void)selectionList:(HTHorizontalSelectionList *)selectionList didSelectButtonWithIndex:(NSInteger)index{
    
    typeStr = [NSString stringWithFormat:@"%ld",index];
    
    typeStr = statusArray[index];
    NSLog(@"typeStr === %@",typeStr);
    _page =1;
    
    
    [self requestDataForNet];
    [UIView animateWithDuration:0.6 animations:^{
        
        _scrollView.contentOffset =CGPointMake(WIDTH * index, 0);
    }];
    UITableView *tableViwe=(id)[self.view viewWithTag:1000+index];
    [tableViwe reloadData];
    
}
//返回下表对应的文字按钮
-(NSString *)selectionList:(HTHorizontalSelectionList *)selectionList titleForItemWithIndex:(NSInteger)index{
    
    return _titileArray[index];
}
//多少个
-(NSInteger)numberOfItemsInSelectionList:(HTHorizontalSelectionList *)selectionList{
    
    return _titileArray.count;
    
}

#pragma mark------tableViewdelegate----

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return allOrderArray.count;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSDictionary * allDic = allOrderArray[section];
    NSArray * array = allDic[@"product"];
    return array.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 100;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSDictionary * allDic = allOrderArray[indexPath.section];
    
    NSArray * array = allDic[@"product"];
    NSDictionary * dic = array[indexPath.row];
    
    OrderTableViewCell  * cell = [tableView dequeueReusableCellWithIdentifier:[OrderTableViewCell reuseIdentifier] forIndexPath:indexPath];
    
    [cell.goodsImage sd_setImageWithURL:ImageUrl(dic[@"cover_photo"]) placeholderImage:ImageName(@"")];
    cell.goodsName.text = dic[@"product_name"];
    cell.goodsName.frame = CGRectMake(98, 10, WIDTH -160, 20);
    cell.goodsName.numberOfLines = 2;
    [cell.goodsName sizeToFit];
    cell.priceLabel.text = [NSString stringWithFormat:@"￥%@",dic[@"price"]];
    cell.numberLabel.text = [NSString stringWithFormat:@"X%@",dic[@"number"]];
    cell.guigeLabel.text = [NSString stringWithFormat:@"%@",dic[@"option_name"]];
    
    cell.numberLabel.frame = CGRectMake(WIDTH-50, 10, 40, 20);
    
    UIButton * commentBtn;
    
    if ([allDic[@"status_value"] isEqualToString:@"wait_comment"]) {
        
        
        if ([dic[@"comment_status"] isEqualToString:@"2"]) {
        
            commentBtn = [self creatCommentBtnFrame:CGRectMake(WIDTH-90,60, 80, 30) andTitleStr:@"立即评价" andSel:@selector(commentBtn:) andBtnTag:indexPath.section * 100 + indexPath.row onView:cell];
            
        }else{
            
            [commentBtn removeFromSuperview];
        }
    }else {
        
        
        UIView * view = [[UIView alloc]initWithFrame: CGRectMake(WIDTH-90,60, 80, 30)];
        
        
        view.backgroundColor = [UIColor whiteColor];
        [cell addSubview:view];
    }
   
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 90;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 90;
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView * heardView =[[UIView alloc]initWithFrame:CGRectMake(0, 0,WIDTH,90)];
    heardView.backgroundColor =[UIColor groupTableViewBackgroundColor];
    
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 10, WIDTH, 90)];
    bgView.backgroundColor = [UIColor whiteColor];
    
    [heardView addSubview:bgView];
    NSDictionary * dataDic = allOrderArray[section];
    
    NSDictionary * dic = dataDic;
    
    
    UILabel * shopName =[[UILabel alloc]initWithFrame:CGRectMake(10, 15, WIDTH - 150, 20)];
    shopName.font =[UIFont systemFontOfSize:16];
    shopName.text = [NSString stringWithFormat:@"订单编号：%@",dic[@"order_sn"]];
    [bgView addSubview:shopName];
    
    UILabel * timeLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, 50, WIDTH - 150, 20)];
    timeLabel.font =[UIFont systemFontOfSize:16];
    timeLabel.text = [NSString stringWithFormat:@"变更时间：%@",dic[@"update_time"]];
    [bgView addSubview:timeLabel];
    
    UILabel * type =[[UILabel alloc]initWithFrame:CGRectMake(WIDTH-110, 35, 100, 20)];
    type.font =[UIFont systemFontOfSize:16];
    
    type.textColor = NavBackColor;
    type.textAlignment = NSTextAlignmentRight;
    type.text = dic[@"status_string"];
    
    [bgView addSubview:type];
    return heardView;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView * footerView =[[UIView alloc]initWithFrame:CGRectMake(0, 0,WIDTH,90)];
    footerView.backgroundColor =[UIColor whiteColor];
    
    NSDictionary * dataDic = allOrderArray[section];
    
    NSDictionary * dic = dataDic;

    
    UILabel * price =[[UILabel alloc]initWithFrame:CGRectMake(WIDTH-160,10,150 , 20)];
    price.font =[UIFont systemFontOfSize:15];
    price.textAlignment = NSTextAlignmentRight;
    
    price.text = [NSString stringWithFormat:@"合计:￥%@",dic[@"order_price"]];
    [footerView addSubview:price];
    
    UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0, 45, WIDTH, 45)];
    view.backgroundColor =[UIColor whiteColor];
    [footerView addSubview:view];
    
    if ([dic[@"status"] isEqualToString:@"unpay"]) {
        [self creatBoardBtnFrame:CGRectMake(WIDTH-270,15/2, 80, 30) andTitleSte:@"查看订单" andSEL:@selector(lookMessageBtn:) andBtnTag:section onView:view];
        
        [self creatBoardBtnFrame:CGRectMake(WIDTH-180,15/2, 80, 30) andTitleSte:@"取消订单" andSEL:@selector(cannleOrderBtn:) andBtnTag:section onView:view];
        
        [self creatRedBtnFrame:CGRectMake(WIDTH-90,15/2, 80, 30) andTitleStr:@"立即付款" andSel:@selector(payForBtn:) andBtnTag:section onView:view];
    }
    if ([dic[@"status"] isEqualToString:@"payed"]) {
        [self creatBoardBtnFrame:CGRectMake(WIDTH-90,15/2, 80, 30) andTitleSte:@"查看订单" andSEL:@selector(lookMessageBtn:)andBtnTag:section  onView:view];
    }
    
    if ([dic[@"status"] isEqualToString:@"deliver"]) {
        [self creatBoardBtnFrame:CGRectMake(WIDTH-180,15/2, 80, 30) andTitleSte:@"查看订单" andSEL:@selector(lookMessageBtn:)andBtnTag:section  onView:view];
        [self creatRedBtnFrame:CGRectMake(WIDTH-90,15/2, 80, 30) andTitleStr:@"确认收货" andSel:@selector(sureShouhBtn:) andBtnTag:section onView:view];
    }
    if ([dic[@"status"] isEqualToString:@"wait_comment"]) {
        [self creatBoardBtnFrame:CGRectMake(WIDTH-90,15/2, 80, 30) andTitleSte:@"查看订单" andSEL:@selector(lookMessageBtn:) andBtnTag:section onView:view];
    }
    
    if ([dic[@"status"] isEqualToString:@"done"]) {
        [self creatBoardBtnFrame:CGRectMake(WIDTH-180,15/2, 80, 30) andTitleSte:@"查看订单" andSEL:@selector(lookMessageBtn:) andBtnTag:section onView:view];
        
        [self creatBoardBtnFrame:CGRectMake(WIDTH-90,15/2, 80, 30) andTitleSte:@"删除订单" andSEL:@selector(deledateOrderBtn:) andBtnTag:section onView:view];
    }
    
    
    return footerView;
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    //    ChangeOrderDetalViewController * changeOrder =[[ChangeOrderDetalViewController alloc]init];
    //    changeOrder.orderSnStr = dic[@"order_sn"];
    //    [self.navigationController pushViewController:changeOrder animated:NO];
    
    
}
#pragma mark 订单操作


-(void)commentBtn:(UIButton *)btn {
    
    NSDictionary * dataDic = allOrderArray[btn.tag/100];
    currySectionDic = dataDic;
    curryRowDic = dataDic[@"product"][btn.tag%100];
    
    NSLog(@"currySectionDic  = %@  curryRowDic = %@",currySectionDic,curryRowDic);
    
    [self creatCommentView];
    
}

-(void)lookMessageBtn:(UIButton *)btn{
    
    NSDictionary * dataDic = allOrderArray[btn.tag];
    
    [self getOrderDetailsFor:dataDic[@"order_id"]];
    NSLog(@"lookMessageBtn");
}

-(void)payForBtn:(UIButton *)btn {
    
    NSDictionary * dataDic = allOrderArray[btn.tag];
    
    NSDictionary * dic = dataDic;
    
    ShopPayForViewController * shop = [ShopPayForViewController new];
    shop.dataDic = dic;
    [self.navigationController pushViewController:shop animated:YES];
    
}

-(void)cannleOrderBtn:(UIButton *)btn {
    
    
    NSDictionary * dataDic = allOrderArray[btn.tag];
    
    NSDictionary * dic = dataDic;
    
    [self cancelOrderStatisForStr:dic[@"order_id"]];
}

-(void)deledateOrderBtn:(UIButton *)btn {
    
    NSDictionary * dataDic = allOrderArray[btn.tag];
    
    NSDictionary * dic = dataDic;
    
    [self deledateOrderRequest:dic[@"order_id"]];
    
    NSLog(@"deledateOrderBtn:");
}

-(void)sureShouhBtn:(UIButton *)btn {
    NSDictionary * dataDic = allOrderArray[btn.tag];
    
    NSDictionary * dic = dataDic;
    
    [self surelOrderStatisForStr:dic[@"order_id"]];
    NSLog(@"确认收货");
}

/**
 *  封装边框按钮
 */
-(void)creatBoardBtnFrame:(CGRect)rec andTitleSte:(NSString *)title andSEL:(SEL)Click andBtnTag:
(NSInteger)tag onView:(UIView *)view {
    
    UIButton * deleBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    deleBtn.frame = rec;
    deleBtn.backgroundColor =[UIColor whiteColor];
    [deleBtn setTitle:title forState:UIControlStateNormal];
    [deleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    deleBtn.layer.cornerRadius =15.f;
    deleBtn.layer.masksToBounds =YES;
    deleBtn.layer.borderWidth = 0.5f;
    deleBtn.layer.borderColor = [UIColor blackColor].CGColor;
    deleBtn.tag = tag;
    deleBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [deleBtn addTarget:self action:Click forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:deleBtn];
    
}

-(void)creatRedBtnFrame:(CGRect)rec andTitleStr:(NSString *)title andSel:(SEL)click andBtnTag:
(NSInteger )tag onView:(UIView *)view {
    
    
    UIButton * btn =[UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = rec;
    btn.backgroundColor =[UIColor whiteColor];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:NavBackColor forState:UIControlStateNormal];
    btn.layer.cornerRadius =15.f;
    btn.layer.masksToBounds =YES;
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    btn.layer.borderWidth = 0.5f;
    btn.tag = tag ;
    btn.layer.borderColor = NavBackColor.CGColor;
    [btn addTarget:self action:click forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
}

-(UIButton *)creatCommentBtnFrame:(CGRect)rec andTitleStr:(NSString *)title andSel:(SEL)click andBtnTag:
(NSInteger )tag onView:(UIView *)view {
    
    
    UIButton * btn =[UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = rec;
    btn.backgroundColor =[UIColor whiteColor];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:NavBackColor forState:UIControlStateNormal];
    btn.layer.cornerRadius =15.f;
    btn.layer.masksToBounds =YES;
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    btn.layer.borderWidth = 0.5f;
    btn.tag = tag ;
    btn.layer.borderColor = NavBackColor.CGColor;
    [btn addTarget:self action:click forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    return btn;
    
}

#pragma mark ----内容关联滑块-----


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (alertView.tag ==10000) {
        if (buttonIndex==0) {
            
            [self requestDataForNet];
        }
    }
    
    
}

//获取我的订单
-(void)requestDataForNet {
    
    if (_totailPage != 0) {
        if(_page == _totailPage + 1){
            [_tableView.mj_footer setState: MJRefreshStateNoMoreData];
            
            return ;
        }
    }
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",address_url,get_sellOrderList_api];
    
    NSString * pageStr = [NSString stringWithFormat:@"%d",_page];
    NSDictionary * dic = @{@"mid":USER_DEFAULTGet(@"mid"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"perpage":@"10",
                           @"page":pageStr,
                           @"type":typeStr
                           };
    
    
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
            
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                _totailPage = [responseObject[@"datas"][@"total_page"] intValue];
                if (_page==1) {
                    
                    if (allOrderArray) {
                        
                        [allOrderArray removeAllObjects];
                    }
                    for (NSDictionary * dic in responseObject[@"datas"][@"Lists"]) {
                        
                        [allOrderArray addObject: dic];
                    }
                }else {
                    
                    for (NSDictionary * dic in responseObject[@"datas"][@"Lists"]) {
                        
                        [allOrderArray addObject: dic];
                    }
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    
                    if (allOrderArray.count>0) {
                        noBodyView.hidden =YES;
                    }else {
                        _tableView.mj_footer.hidden = YES;
                        noBodyView.hidden =NO;
                        
                        [self.view addSubview:noBodyView];
                    }
                    [_tableView.mj_header endRefreshing];
                    [_tableView.mj_footer endRefreshing];
                    [_tableView reloadData];
                });
            });
            
        } else {
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        NSLog(@"ERROR ==%@",error);
        SHuiMBhudTextNetError;
    }];
    
    
}

/**
 *  取消订单
 *
 */
-(void)cancelOrderStatisForStr:(NSString *)Ordstr {
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",address_url,cancel_sellOrder_api];
    
    NSDictionary * dic = @{@"order_id":Ordstr,
                           @"token":USER_DEFAULTGet(@"token"),
                           @"mid":USER_DEFAULTGet(@"mid"),
                           };
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
              SHuiMBhudTextTimeStr(@"取消成功！");
            _page = 1;
            [self requestDataForNet];
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        NSLog(@"ERROR ==%@",error);
        SHuiMBhudTextNetError;
    }];
    
}

// 确认收货
-(void)surelOrderStatisForStr:(NSString *)Ordstr {
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",address_url,got_sellOrder_api];
    
    NSDictionary * dic = @{@"order_id":Ordstr,
                           @"token":USER_DEFAULTGet(@"token"),
                           @"mid":USER_DEFAULTGet(@"mid"),
                           };
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
            
            SHuiMBhudTextTimeStr(@"收货成功！");
            _page = 1;
            [self requestDataForNet];
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        NSLog(@"ERROR ==%@",error);
        SHuiMBhudTextNetError;
    }];
    
}


-(void)deledateOrderRequest:(NSString *)str {
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",address_url,deledate_order_api];
    
    NSDictionary * dic = @{@"order_id":str,
                           @"token":USER_DEFAULTGet(@"token"),
                           @"mid":USER_DEFAULTGet(@"mid"),
                           };
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
            
            SHuiMBhudTextTimeStr(@"删除成功！");
            _page = 1;
            [self requestDataForNet];
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        NSLog(@"ERROR ==%@",error);
        SHuiMBhudTextNetError;
    }];
    
}

-(void)getOrderDetailsFor:(NSString *)str{
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",address_url,get_sellOrderDetails_api];
    
    NSDictionary * dic = @{@"mid":USER_DEFAULTGet(@"mid"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"order_id":str,
                           
                           };
    
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
            
            if ([responseObject[@"datas"][@"status"] isEqualToString:@"done"]) {
                
                FruitOrderFinishDetailsVC * details =[[FruitOrderFinishDetailsVC alloc]init];
                details.dataDic = responseObject[@"datas"];
                [self.navigationController pushViewController:details animated:YES];
            }else if([responseObject[@"datas"][@"status"] isEqualToString:@"deliver"]||[responseObject[@"datas"][@"status"] isEqualToString:@"wait_comment"]){
                
                FruitOrderEmsDetailsVC * details =[[FruitOrderEmsDetailsVC alloc]init];
                details.dataDic = responseObject[@"datas"];
                [self.navigationController pushViewController:details animated:YES];
            }else{
                
                FruitOrderDetailsViewController * details =[[FruitOrderDetailsViewController alloc]init];
                details.dataDic = responseObject[@"datas"];
                [self.navigationController pushViewController:details animated:YES];
            }
            
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        NSLog(@"ERROR ==%@",error);
        SHuiMBhudTextNetError;
    }];
    
}
// 评论
-(void)requestMessageForNetOrdSn:(NSString *)ordsn andProductStr:(NSString *)proStr{
    
    NSDictionary * dic = @{@"mid":USER_DEFAULTGet(@"mid"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"content":self.sztTextView.text,
                           @"order_id":currySectionDic[@"order_id"],
                           @"product_id":curryRowDic[@"product_id"]
                           };
    SHuiMBhubNoTimeStr(@"正在提交...");
    [PostNetWorking postNetWorkingStr:RequestUrlStr(comment_sellOrder_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            SHuiMBhudTextTimeStr(@"提交成功！");
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW , (1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
                    
                   
                });
            });
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
    }];
    
}

@end
